const _config = module.exports

_config.provider = async (args ={}) => {
    let where = {
        is_delete: 1,
        is_enable: 1,
    };

    return await dbUtil.getAll('dic_notice_provider', where, '-created_at')
}

_config.sign = async (args ={}) => {
    let where = {
        is_delete: 1,
        is_enable: 1,
    };

    if(!!_.get(args, 'provider_code')) {
        where.provider_code = _.get(args, 'provider_code')
    }

    if(!!_.get(args, 'way_code')) {
        where.way_code = _.get(args, 'way_code')
    }

    return await dbUtil.getAll('dic_notice_sign', where, '-created_at', [
        {
            model: 'dic_notice_provider',
            foreignKey: 'provider_code',
            targetKey: 'code',
            as: 'provider_info',
        },
        {
            model: 'dic_notice_way',
            foreignKey: 'way_code',
            targetKey: 'way_code',
            as: 'way_info',
            attributes:'-app_key -app_secret -callback'
        },
    ])
}

_config.template = async (args ={}) => {
    let where = {
        is_delete: 1,
        is_enable: 1,
    };

    if(!!_.get(args, 'provider_code')) {
        where.provider_code = _.get(args, 'provider_code')
    }

    if(!!_.get(args, 'way_code')) {
        where.way_code = _.get(args, 'way_code')
    }

    return await dbUtil.getAll('dic_notice_template', where, '-created_at', [
        {
            model: 'dic_notice_provider',
            foreignKey: 'provider_code',
            targetKey: 'code',
            as: 'provider_info',
        },
        {
            model: 'dic_notice_way',
            foreignKey: 'way_code',
            targetKey: 'way_code',
            as: 'way_info',
            attributes:'-app_key -app_secret -callback'
        },
    ])
}

_config.way = async (args ={}) => {
    let where = {
        is_delete: 1,
        is_enable: 1,
    };

    if(!!_.get(args, 'provider_code')) {
        where.provider_code = _.get(args, 'provider_code')
    }

    return await dbUtil.getAll('dic_notice_way', where, '-created_at', [
        {
            model: 'dic_notice_provider',
            foreignKey: 'provider_code',
            targetKey: 'code',
            as: 'provider_info',
        },
    ],'-app_key -app_secret -callback')
}
